/**
 * 浅拷贝
 */

//class Person implements Cloneable{
//     public int id = 1314521;
//
//    @Override
//    protected Object clone() throws CloneNotSupportedException {
//        return super.clone();
//    }
//
//    @Override
//    public String toString() {
//        return "person1{" +
//                "id=" + id +
//                '}';
//    }
//}
//
//public class TestDemo {
//
//    public static void main(String[] args) throws CloneNotSupportedException {
//        Person person1 = new Person();
//        Person person2 = (Person)person1.clone();
//        System.out.println(person2);
//    }
//}

///**
// * 深拷贝
// */
//class Money implements Cloneable{
//    public int m =99;
//
//    @Override
//    protected Object clone() throws CloneNotSupportedException {
//        return super.clone();
//    }
//
//    @Override
//    public String toString() {
//        return "Money{" +
//                "m=" + m +
//                '}';
//    }
//}
//
//class Person implements Cloneable{
//    public int id = 1314521;
//    Money money = new Money();
//    @Override
//    protected Object clone() throws CloneNotSupportedException {
//        Person tmp = (Person)super.clone();
//        tmp.money=(Money)this.money.clone();
//        return tmp;
//    }
//
//    @Override
//    public String toString() {
//        return "person{" +
//                "id=" + id +
//                '}';
//    }
//}
//
//public class TestDemo {
//
//    public static void main(String[] args) throws CloneNotSupportedException {
//        Person person1 = new Person();
//        Person person2 = (Person)person1.clone();
//        System.out.println(person1.money.m);
//        System.out.println(person2.money.m);
//        System.out.println("++++++++++++++++++++");
//        person1.money.m=9;
//        System.out.println(person1.money.m);
//        System.out.println(person2.money.m);
////        System.out.println(person1.money.m);
////        System.out.println(person2.money.m);
//        //System.out.println(person2);
//    }
//}

////浅拷贝
//class SmartPhone{
//    public int money = 9999;
//}
//
//class Person implements  Cloneable{
//    public int score = 96;
//    SmartPhone smartPhone = new SmartPhone();
//
//    @Override
//    protected Object clone() throws CloneNotSupportedException {
//        return super.clone();
//    }
//
//    @Override
//    public String toString() {
//        return "Person{" +
//                "score=" + score +
//                ", smartPhone=" + smartPhone +
//                '}';
//    }
//}
//
//public class TestDemo {
//
//    public static void main(String[] args) throws CloneNotSupportedException {
//        Person person1 = new Person();
//        Person person2 = (Person)person1.clone();
//        System.out.println(person1.smartPhone.money);
//        System.out.println(person2.smartPhone.money);
//        person1.smartPhone.money=9;
//        System.out.println("===============拷贝之后=================");
//        System.out.println(person1.smartPhone.money);
//        System.out.println(person2.smartPhone.money);
//    }
//}

//深拷贝
class SmartPhone implements  Cloneable{
    public int money = 9999;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public String toString() {
        return "SmartPhone{" +
                "money=" + money +
                '}';
    }
}
class Person implements  Cloneable{
    public int score = 96;
    SmartPhone smartPhone = new SmartPhone();

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person tmp = (Person)super.clone();
        tmp.smartPhone= (SmartPhone) this.smartPhone.clone();
        return tmp;
    }

    @Override
    public String toString() {
        return "Person{" +
                "score=" + score +
                ", smartPhone=" + smartPhone +
                '}';
    }
}

public class TestDemo {

    public static void main(String[] args) throws CloneNotSupportedException {
        Person person1 = new Person();
        Person person2 = (Person)person1.clone();
        System.out.println(person1.smartPhone.money);
        System.out.println(person2.smartPhone.money);
        person1.smartPhone.money=9;
        System.out.println("===============拷贝之后=================");
        System.out.println(person1.smartPhone.money);
        System.out.println(person2.smartPhone.money);
    }
}